<template>
  <div>
    <form @submit.prevent="handleLogin">
      <input type="text" v-model="username" />
      <input type="text" v-model="password" />
      <button type="submit">登录</button>
    </form>
  </div>
</template>

<script>
import { ref } from "@vue/reactivity";
import { useRouter } from "vue-router";
import axios from "axios";
export default {
  setup() {
    const router = useRouter();
    // const route = useRoute();
    // const store = useStore();

    const username = ref("");
    const password = ref("");

    const handleLogin = async () => {
      const resp = await axios.post("/api/login", {
        username: username.value,
        password: password.value,
      });

      const { code } = resp.data;

      if (code === 200) {
        router.push({ name: "my" });
      } else {
        alert("账户密码错误！！！");
      }
    };
    return {
      username,
      password,
      handleLogin,
    };
  },
};
</script>
